package lu.uni.adtool.ui;

import java.awt.Frame;

import lu.uni.adtool.domains.rings.BoundedInteger;

public class BoundedIntegerInfDialog extends BoundedIntegerDialog
{
  static final long serialVersionUID = 35393957497521214L;

  /**
   * {@inheritDoc}
   * @see BoundedIntegerDialog#BoundedIntegerInfDialog(Frame)
   */
  public BoundedIntegerInfDialog(final Frame frame)
  {
    super(frame,"Enter non-negative integer number");
  }
  /**
   * {@inheritDoc}
   * @see BoundedIntegerDialog#BoundedIntegerInfDialog(Frame,String)
   */
  public BoundedIntegerInfDialog(final Frame frame,final String title)
  {
    super(frame,title);
  }
  /**
   * {@inheritDoc}
   * @see BoundedIntegerDialog#createLayout(boolean)
   */
  protected final void createLayout(final boolean showDefault)
  {
    super.createLayout(showDefault);
    errorMsg.setText(errorMsg.getText()+" Infinity value is also allowed.");
    infButton.setEnabled(true);
  }
  /**
   * {@inheritDoc}
   * @see InputDialog#isValid(double)
   */
  protected final boolean isValid(final double d)
  {
    boolean isValid = false;
    final int bound = ((BoundedInteger)value).getBound();
    if(new Double(d).isInfinite()){
      isValid = true;
    }
    else if(d >= 0 && d<=bound){
      isValid = true;
    }
    return isValid;
  }
}

